package com.jsmy.softapp.fragment;

import android.support.v4.app.Fragment;

import com.alibaba.android.arouter.launcher.ARouter;
import com.jsmy.softapp.aroute.AR;

/**
 * Created with Android Studio.
 * User: wei_cd.
 * Date: 2018/4/18.
 * Time: 12:27.
 * To change for file | settings | file and code templates.
 */

public class FragmentSmanager {
    private volatile static FragmentSmanager smanager;

    private FragmentSmanager() {
    }

    public static FragmentSmanager getInstance() {
        if (smanager == null) {
            synchronized (FragmentSmanager.class) {
                if (smanager == null) {
                    smanager = new FragmentSmanager();
                }
            }
        }
        return smanager;
    }

    private HomeFragment homeFragment;
    public static final String HOME = "HOME";

    private DataFragment dataFragment;
    public static final String DATA = "DATA";

    private BusinessFragment businessFragment;
    public static final String BUSINESS = "BUSINESS";

    private PlantFragment  plantFragment;
    public static final String PLANT = "PLANT";

    private DailyFragment dailyFragment;
    public static final String DAILY = "DAILY";

    private KHPlantFragment  khplantFragment;
    public static final String KHPLANT = "KHPLANT";

    private KHDailyFragment khdailyFragment;
    public static final String KHDAILY = "KHDAILY";

    private ZiLiaoFragment ziLiaoFragment;
    public static final String ZILIAO = "ZILIAO";

    public Fragment getFragment(String FragTag) {

        if (FragTag.equals(HOME)) {
            if (homeFragment == null) {
                synchronized (FragmentSmanager.class) {
                    if (homeFragment == null) {
                        homeFragment = (HomeFragment) ARouter.getInstance().build(AR.F_HOME).navigation();
                    }
                }

            }
            return homeFragment;
        }

        if (FragTag.equals(DATA)) {
            if (dataFragment == null) {
                synchronized (FragmentSmanager.class) {
                    if (dataFragment == null) {
                        dataFragment = (DataFragment) ARouter.getInstance().build(AR.F_DATA).navigation();
                    }
                }

            }
            return dataFragment;
        }

        if (FragTag.equals(BUSINESS)) {
            if (businessFragment == null) {
                synchronized (FragmentSmanager.class) {
                    if (businessFragment == null) {
                        businessFragment = (BusinessFragment) ARouter.getInstance().build(AR.F_BUSINESS).navigation();
                    }
                }
            }
            return businessFragment;
        }

        if (FragTag.equals(PLANT)) {
            if (plantFragment == null) {
                synchronized (FragmentSmanager.class) {
                    if (plantFragment == null) {
                        plantFragment = (PlantFragment) ARouter.getInstance().build(AR.F_PLANT).navigation();
                    }
                }
            }
            return plantFragment;
        }

        if (FragTag.equals(DAILY)) {
            if (dailyFragment == null) {
                synchronized (FragmentSmanager.class) {
                    if (dailyFragment == null) {
                        dailyFragment = (DailyFragment) ARouter.getInstance().build(AR.F_DAILY).navigation();
                    }
                }
            }
            return dailyFragment;
        }

        if (FragTag.equals(KHPLANT)) {
            if (khplantFragment == null) {
                synchronized (FragmentSmanager.class) {
                    if (khplantFragment == null) {
                        khplantFragment = (KHPlantFragment) ARouter.getInstance().build(AR.F_KHPLANT).navigation();
                    }
                }
            }
            return khplantFragment;
        }

        if (FragTag.equals(KHDAILY)) {
            if (khdailyFragment == null) {
                synchronized (FragmentSmanager.class) {
                    if (khdailyFragment == null) {
                        khdailyFragment = (KHDailyFragment) ARouter.getInstance().build(AR.F_KHDAILY).navigation();
                    }
                }
            }
            return khdailyFragment;
        }

        if (FragTag.equals(ZILIAO)) {
            if (ziLiaoFragment == null) {
                synchronized (FragmentSmanager.class) {
                    if (ziLiaoFragment == null) {
                        ziLiaoFragment = (ZiLiaoFragment) ARouter.getInstance().build(AR.F_ZILIAO).navigation();
                    }
                }
            }
            return ziLiaoFragment;
        }
        return null;
    }
}
